import React from 'react';
import './index.css';
import UserInfoHeader from "../../../Component/UserInfoHeader";
import { Input, Select,Button } from 'antd';
import UserServer from "../../../Server/User";
import UserCheck from '../../../utils/UserCheck';

const { Option } = Select;

export default class Certificate extends React.Component{
    constructor(props){
        super();
        this.state={
            name:"",
            area:"中国大陆",
            type:"身份证",
            id:"",
            err:""
        }
        //判断用户是否认证
        UserServer.SelectAuthenticationInformation(UserCheck.GetUserID())
        .then(response=>{
            //redirect
            //已经认证过,跳转
            
            let frame=window.parent.document.getElementById("Layout_MainContainer");
            frame.src="/ca";
        },reject=>{
            
        })
    }
    Save(){
        UserServer.UserRealNameAuthentication(UserCheck.GetUserID(),
        this.state.area,this.state.type,this.state.name,this.state.id)
        .then(response=>{
            // this.SetErr("认证成功");
            this.setState({
                err:"认证成功,即将跳转"
            },()=>{
                setInterval(()=>{
                    let frame=window.parent.document.getElementById("Layout_MainContainer");
                    frame.src="/ca";
                },3000)
            });
            console.log(response)
        },reject=>{
            this.SetErr(reject.msg);
        });
    }
    AddCA(){
        if(this.Check()){
            this.Save();
        }
    }
    SetErr(value){
        this.setState({
            err:value
        });
    }
    Clear(){
        this.setState({
            err:""
        });
    }
    Check(){
        if(this.state.area!==""&&this.state.area!==""&&this.state.name!==""&&this.state.id!==""){
            return true;
        }
        this.SetErr("请填写完整");
        return false;
    }
    render(){
        return(
            <div>
                <div><UserInfoHeader/></div>
                <div className="Certificate_Down">
                    <div className="Certificate_Down_Input">
                        <span className="Certificate_Down_Title">国籍(地区)</span>
                        <div className="Certificate_Down_Body">
                            <Select placeholder="请选择"  onChange={e=>this.setState({area:e})} defaultValue="中国大陆" style={{ width: '100%' }}>
                                <Option value="中国大陆">中国大陆</Option>
                            </Select>
                        </div>
                    </div>
                    <div className="Certificate_Down_Input">
                        <span className="Certificate_Down_Title">证件类型</span>
                        <div className="Certificate_Down_Body">
                            <Select placeholder="请选择" onChange={e=>this.setState({type:e})} defaultValue="身份证" style={{ width: '100%' }}>
                                <Option value="身份证">身份证</Option>
                                <Option value="护照">护照</Option>
                            </Select>
                        </div>
                    </div>
                    <div className="Certificate_Down_Input">
                        <span className="Certificate_Down_Title">姓名</span>
                        <div className="Certificate_Down_Body">
                            <Input placeholder="请输入姓名" onChange={e=>this.setState({name:e.target.value})} value={this.state.name}/>
                        </div>
                    </div>
                    <div className="Certificate_Down_Input">
                        <span className="Certificate_Down_Title">证件号码</span>
                        <div className="Certificate_Down_Body">
                            <Input placeholder="请输入证件号码" onChange={e=>this.setState({id:e.target.value})} value={this.state.id} />
                        </div>
                    </div>
                    <div>
                        <font color="red">{this.state.err}</font>
                    </div>
                </div>
                <div className="Certificate_Down_Button">
                    <Button onClick={e=>this.AddCA(e)}>提交认证</Button>
                </div>
                <div className="Certificate_Down_Remark">
                    <span>*</span>
                    <span>请仔细填写您的个人信息，验证完成后不可修改</span>
                </div>
            </div>
        )
    }
}